import { _decorator, Button, Label, size, Sprite, UITransform } from 'cc';
import { Ab_BasePopUp_bA } from '../../../A-FRAME/component/ui.pop-up';
import Ab_Config_bA from '../../manager/config.manager';
import Ab_GameAssets_bA from '../../manager/game.assets';
import type { Ab_Popup_bA } from '../page/popup';
const { ccclass, property } = _decorator;

@ccclass('Ab_Defeat_bA')
export class Ab_Defeat_bA extends Ab_BasePopUp_bA<typeof Ab_Popup_bA, null> {
	protected Ab_default_return_bA: null;

	private lbl_round: Label;
	private lbl_symbol: Label;

	protected Ab_initAfterOnLoad_bA(){
		this.lbl_round = this.node.getChildByName('lbl-round').getComponent(Label);
		this.lbl_symbol = this.node.getChildByName('lbl-symbol').getComponent(Label);
		this.Ab_renderLocalUI_bA();
	}

	protected Ab__click_event__bA: { [name: string]: (this: Ab_Defeat_bA, button: Button) => void; } = {
		close(btn){
			btn.interactable = false;
			Ab_BasePopUp_bA.Ab_jelly_leave_bA(this.node).then(()=>{
				this.Ab_close_bA(null);
				btn.interactable = true;
			});
		}
	}

	public Ab_onShow_bA(round: number, symbol: number){
		this.lbl_round.string = Ab_GameAssets_bA.Ab_getLangText_bA(0, round);
		this.lbl_symbol.string = Ab_Config_bA.Ab_symbolString_bA(symbol);
		Ab_BasePopUp_bA.Ab_jelly_enter_bA(this.node);
	}

	private Ab_renderLocalUI_bA(){
		(<const>[
			['close', 12],
			['desc', 11]
		]).forEach(([name, idx])=>this.node.getChildByName('lbl-'+name).getComponent(Label).string = Ab_GameAssets_bA.Ab_getLangText_bA(idx));

		let ui_title = this.node.getChildByName('title').getComponent(UITransform);
		let title_size = size(
			this.node.getChildByName('background-head').getComponent(UITransform).width,
			ui_title.height,
		);

		let sframe = Ab_GameAssets_bA.Ab_getLangTexture_bA(1);

		let scale = Math.min(title_size.width/sframe.originalSize.width, title_size.height/sframe.originalSize.height);

		ui_title.getComponent(Sprite).spriteFrame = sframe;

		ui_title.setContentSize(
			sframe.originalSize.width*scale,
			sframe.originalSize.height*scale
		);

		let ui_icon = this.node.getChildByName('icon').getComponent(UITransform);
		abi.Ab_cc_bA.Ab_skinPeeler_bA(ui_icon.node, Ab_GameAssets_bA.Ab_getCounTexture_bA(1), {height: true});
		ui_icon.setContentSize(ui_icon.width * 0.8, ui_icon.height * 0.8);
	}
}

